<?php
	namespace Common\Logic;
	use Common\Model\UserGalleryCommentModel;
	class UserGalleryCommentLogic extends UserGalleryCommentModel{
		/*
		* Function:		getUserGalleryCommentList
		* Description:	画廊评论列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getUserGalleryCommentList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getUserGalleryCommentFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getUserGalleryCommentFilter
		* Description:	画廊评论列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getUserGalleryCommentFilter($filter = ''){
			$conditon = array();
         $conditon['is_deleted'] = 0;
			if(!empty($filter['nid'])){
				$conditon['nid'] = array('in',$filter['nid']);
			}
			if(!empty($filter['tid'])){
				$conditon['tid'] = $filter['tid'];
			}
			if(!empty($filter['content'])){
				$conditon['content'] = array('like','%'.$filter['content'].'%');
			}
         	if($filter['status']!=''){
				$conditon['status'] = $filter['status'];
			}
         	if(!empty($filter['username'])){
				$wh = array();
				$wh['username'] = array('like','%'.$filter['username'].'%');
				$sql = D('User')->field('id')->where($wh)->select(false);
				$conditon['user_id'] = array('exp','in('.$sql.')');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getUserGalleryCommentCount
		* Description:	画廊评论列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getUserGalleryCommentCount($filter = ''){
			$conditon = $this->getUserGalleryCommentFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addUserGalleryComment
		* Description:	增加画廊评论
		* @param:		$data array 增加的数组
		*/
		public function addUserGalleryComment($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getUserGalleryCommentInfo
		* Description:	获取画廊评论信息 by row
		* @param:		$id int ID
		*/
		public function getUserGalleryCommentInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateUserGalleryComment
		* Description:	更新画廊评论
		* @param:		$data array 更新的数组
		*/
		public function updateUserGalleryComment($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteUserGalleryComment
		* Description:	删除画廊评论
		* @param:		$id int ID
		*/
		public function deleteUserGalleryComment($id){
			return $this->where(array('id'=>$id))->delete();
		}

		/*
		* Function:		getUserGalleryCommentSum
		* Description:	更新画廊评论
		* @param:		$data array 更新的数组
		*/
		public function getUserGalleryCommentSum($tid = '',$type = 1){
			return $this->where(['status'=>1,'tid'=>$tid,'type'=>$type])->count();
		}
	}
?>